<template>
  <header>
    <div class="wrapper">
      <!-- 菜单图标 -->
      <div class="menu-icon" @click="handleMenuClick">
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
        >
          <path
            d="M3 12H21M3 6H21M3 18H21"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
          />
        </svg>
      </div>

      <!-- <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav> -->
    </div>
  </header>

  <RouterView />

  <!-- 侧边抽屉菜单 -->
  <SiderMenu ref="siderMenuRef" />
</template>
<script setup lang="ts">
import { RouterView } from 'vue-router'
import { ref } from 'vue'
import SiderMenu from './components/SiderMenu.vue'

// 定义 SiderMenu 组件的类型
interface SiderMenuInstance {
  toggleDrawer: () => void
  openDrawer: () => void
  closeDrawer: () => void
}

// 获取抽屉组件的引用
const siderMenuRef = ref<SiderMenuInstance>()

// 点击菜单图标打开抽屉
const handleMenuClick = () => {
  siderMenuRef.value?.toggleDrawer()
}
</script>
<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

/* 菜单图标样式 */
.menu-icon {
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 1rem;
}

.menu-icon:hover {
  background-color: var(--color-background-soft);
}

.menu-icon svg {
  color: var(--color-text);
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
    align-items: center;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;
    padding: 1rem 0;
    margin-top: 1rem;
  }

  .menu-icon {
    margin-top: 1rem;
  }
}
</style>
